package com.example.demo.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;

@Repository("stuDao")
public class StuDaoImp implements StuDao{
  private JdbcTemplate jdbcTemplate;
  @Autowired(required=false)
  public void setDataSource(DataSource dataSource){
    this.jdbcTemplate=new JdbcTemplate(dataSource);
  }
  @Transactional
  @Override
  public void tx() {
    jdbcTemplate.update("insert into stu(username, java) values('tx-1',90)");
  }
}
